﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.DynamicData;

public partial class Adm_GestTabelle : System.Web.UI.Page
{
  protected string mTabella = "Users";//string.Empty ;
  
		protected void Page_Load(object sender, EventArgs e)
		{
		  this.SqlDataSource1.ConnectionString =
						System.Configuration.ConfigurationManager.ConnectionStrings["baseConnectionString"].ConnectionString;     
		  
		   if(! IsPostBack)
		    { bindTabelle(); 
								this.GridView1.Enabled = false;
								showDati(mTabella); 
						}		

		}

		protected void bindTabelle()
		{
				var visibleTables = MetaModel.Default.Tables;
				if (visibleTables.Count == 0)
						throw new InvalidOperationException("Nessuna tabella trovata");

				//this.GridView1.DataKeyNames = new[] { "Name" };
				this.ListBoxTabelle.DataTextField ="name";
				this.ListBoxTabelle.DataValueField = "name";    
				this.ListBoxTabelle.DataSource = visibleTables;
				this.ListBoxTabelle.DataBind();

		}//fM
		
		protected void showDati(string pTabella )
		{
				//this.EntityDataSource1.ContextTypeName  = "OrmAuto;.DBEntities" ; 
				//this.EntityDataSource1.EntitySetName = pTabella ; 
				//this.EntityDataSource1.EnableUpdate = true ; 
				this.SqlDataSource1.DataSourceMode = SqlDataSourceMode.DataSet ;
				this.SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.Text ; 
				this.SqlDataSource1.SelectCommand ="Select * from "+ mTabella ; 
				 
				this.GridView1.DataKeyNames = new []{"UserID"}; 
				this.GridView1.DataBind();  
		}//fM
		
		
		
		protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
		{

		}
		protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
		{

		}
		protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
		{

		}
		protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
		{

		}
		protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
		{

		}
		protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
		{

		}
		protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
		{

		}
		protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
		{

		}
		protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
		{

		}
		
		
		protected void ListBoxTabelle_SelectedIndexChanged(object sender, EventArgs e)
		{
     mTabella =  ListBoxTabelle.SelectedValue ; 
     showDati(mTabella); 
		}
}
